package com.jf.cloud.order.controller.platform;

import com.jf.cloud.api.user.dto.FinanceDetailDTO;
import com.jf.cloud.api.user.vo.FinanceDetailVO;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.util.ExcelUtil;
import com.jf.cloud.order.service.OrderFinanceService;
import com.jf.cloud.api.user.vo.FinanceDetailExcelVO;
import io.swagger.v3.oas.annotations.Operation;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 财务明细
 * @author zz
 */
@RestController("platformOrderFinanceController")
@RequestMapping("/p/finance")
public class OrderFinanceController {

    @Autowired
    private OrderFinanceService orderFinanceService;

    @GetMapping("/get_finance_detail")
    @Operation(summary = "获取财务明细" , description = "分页获取财务明细")
    public ServerResponseEntity<PageVO<FinanceDetailVO>> getFinanceDetail(@Valid PageDTO pageDTO, @ParameterObject FinanceDetailDTO financeDetailDTO) {
        PageVO<FinanceDetailVO> pageFinanceDetail = orderFinanceService.pageFinanceDetail(pageDTO, financeDetailDTO);
        return ServerResponseEntity.success(pageFinanceDetail);
    }

    @GetMapping("/finance_detail_export")
    @Operation(summary = "导出excel" , description = "导出财务明细")
    public ServerResponseEntity<Void> financeDetailExport(HttpServletResponse response, @ParameterObject FinanceDetailDTO financeDetailDTO) {
        List<FinanceDetailExcelVO> list = orderFinanceService.listExcelFinanceDetail(financeDetailDTO);
        ExcelUtil.soleExcel(response, list, FinanceDetailExcelVO.EXCEL_NAME, FinanceDetailExcelVO.MERGE_ROW_INDEX, FinanceDetailExcelVO.MERGE_COLUMN_INDEX,  FinanceDetailExcelVO.class);
        return ServerResponseEntity.success();
    }
}
